<template>
  <view class="chooseCar-container">
    <!-- 页面标题 -->
    <view class="header">
      <text class="page-title">选择车型</text>
      <text class="subtitle">请选择您的车辆类型</text>
    </view>

    <!-- 车型选择区域 -->
    <view class="car-types">
      <view
        v-for="car in cars"
        :key="car.id"
        class="car-type-card"
        :class="{ active: selectedCarType === car.id }"
        @click="selectCarType(car.id)"
      >
        <view class="car-image-container">
          <image
            class="car-image"
            :src="car.carType.img"
            mode="aspectFit"
          ></image>
        </view>
        <view class="car-info">
          <text class="car-name">{{ car.brandName }}:{{ car.carType.name }}</text>
          <text class="car-description">{{ car.carNum }}</text>
        
        </view>
        <view class="select-indicator">
          <text class="check-icon" v-if="selectedCarType === car.id">✓</text>
        </view>
      </view>
    </view>

    <!-- 已选车型信息 -->
    <view class="selected-info" v-if="selectedCarType">
      <view class="info-header">
        <text class="info-title">已选车型信息</text>
      </view>
      <view class="selected-car-details">
        <text class="selected-name">{{ selectedCarDetails.brandName }}:{{ selectedCarDetails.carType.name }}</text>
        <text class="selected-desc">车牌号：{{ selectedCarDetails.carNum }}</text>
        <view class="features-list">
          <text
            v-for="feature in selectedCarDetails.features"
            :key="feature"
            class="feature-tag"
          >
            {{ feature }}
          </text>
        </view>
      </view>
    </view>

    <!-- 底部操作栏 -->
    <view class="bottom-bar">
      <button class="cancel-btn" @click="goBack">
        取消
      </button>
      <button 
        class="confirm-btn" 
        :class="{ disabled: !selectedCarType }"
        :disabled="!selectedCarType"
        @click="confirmCarType"
      >
        确认车型
      </button>
    </view>
  </view>
</template>

<script>
import request from '@/utils/request.js';

export default {
  components: {},
  
  data() {
    return {
      selectedCarType: null,
      
      // 车型数据
      cars: [
       
      ]
    }
  },

  computed: {
    selectedCarDetails() {
      if (this.selectedCarType) {
        return this.cars.find(car => car.id === this.selectedCarType) || {};
      }
      return {};
    }
  },

  methods: {
    // 选择车型
    selectCarType(carId) {
      this.selectedCarType = carId;
      
      // 添加选择音效（如果需要）
      uni.vibrateShort();
    },

    // 确认车型选择
    confirmCarType() {
      if (!this.selectedCarType) {
        uni.showToast({
          title: '请先选择车型',
          icon: 'none'
        });
        return;
      }

      // 保存选择的车型信息
      const selectedCar = this.selectedCarDetails;
      uni.setStorageSync('theCar', selectedCar);

      // 显示确认提示
     this.goBack();
    },

    // 返回上一页
    goBack() {
      uni.navigateBack({
        delta: 1
      });
    }
  },

  // 页面周期函数
  onLoad() {
    request({
      url: '/pyh/info/listByUser',
      method: 'GET'
    }).then(res => {
      if (res.code === 200) {
        this.cars = res.data.rows;
        console.log(res)
      }
    })
    // 页面加载时检查是否已有选中的车型
 
  },

  onShow() {
    // 页面显示时的逻辑
  },

  onHide() {
    // 页面隐藏时的逻辑
  },

  onUnload() {
    // 页面卸载时的逻辑
  }
}
</script>

<style scoped>
.chooseCar-container {
  min-height: 100vh;
  background: #f5f5f5;
  display: flex;
  flex-direction: column;
}

/* 页面头部 */
.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 40rpx 30rpx;
  text-align: center;
}

.page-title {
  font-size: 36rpx;
  font-weight: bold;
  display: block;
  margin-bottom: 10rpx;
}

.subtitle {
  font-size: 28rpx;
  opacity: 0.9;
}

/* 车型选择区域 */
.car-types {
  flex: 1;
  padding: 20rpx;
}

.car-type-card {
  background: white;
  border-radius: 20rpx;
  margin-bottom: 20rpx;
  padding: 30rpx;
  display: flex;
  align-items: center;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
}

.car-type-card.active {
  border: 2rpx solid #667eea;
  box-shadow: 0 6rpx 20rpx rgba(102, 126, 234, 0.2);
}

.car-type-card:active {
  /* 移除点击缩放效果 */
}

/* 车型图片 */
.car-image-container {
  width: 120rpx;
  height: 120rpx;
  border-radius: 15rpx;
  background: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 30rpx;
  overflow: hidden;
}

.car-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 车型信息 */
.car-info {
  flex: 1;
}

.car-name {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
  display: block;
  margin-bottom: 8rpx;
}

.car-description {
  font-size: 26rpx;
  color: #666;
  display: block;
  margin-bottom: 10rpx;
}

.car-price {
  font-size: 28rpx;
  color: #e74c3c;
  font-weight: bold;
}

/* 选择指示器 */
.select-indicator {
  width: 60rpx;
  height: 60rpx;
  border-radius: 50%;
  border: 2rpx solid #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  transition: all 0.3s ease;
}

.car-type-card.active .select-indicator {
  border-color: #667eea;
  background: #667eea;
}

.check-icon {
  color: white;
  font-size: 28rpx;
  font-weight: bold;
}

/* 已选车型信息 */
.selected-info {
  background: white;
  margin: 0 20rpx;
  border-radius: 15rpx;
  padding: 30rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
}

.info-header {
  border-bottom: 1rpx solid #eee;
  padding-bottom: 20rpx;
  margin-bottom: 20rpx;
}

.info-title {
  font-size: 30rpx;
  font-weight: bold;
  color: #333;
}

.selected-car-details {
  text-align: center;
}

.selected-name {
  font-size: 34rpx;
  font-weight: bold;
  color: #667eea;
  display: block;
  margin-bottom: 10rpx;
}

.selected-desc {
  font-size: 26rpx;
  color: #666;
  display: block;
  margin-bottom: 20rpx;
}

.features-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10rpx;
}

.feature-tag {
  background: #f0f2ff;
  color: #667eea;
  padding: 8rpx 16rpx;
  border-radius: 20rpx;
  font-size: 24rpx;
}

/* 底部操作栏 */
.bottom-bar {
  background: white;
  padding: 30rpx;
  border-top: 1rpx solid #eee;
  display: flex;
  gap: 20rpx;
}

.cancel-btn, .confirm-btn {
  flex: 1;
  height: 80rpx;
  border-radius: 40rpx;
  font-size: 30rpx;
  border: none;
  transition: all 0.3s ease;
}

.cancel-btn {
  background: #f5f5f5;
  color: #666;
}

.cancel-btn:active {
  background: #e0e0e0;
}

.confirm-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-weight: bold;
}

.confirm-btn:active {
  transform: scale(0.95);
}

.confirm-btn.disabled {
  background: #ccc;
  color: #999;
}

.confirm-btn[disabled] {
  background: #ccc;
  color: #999;
}

/* 响应式设计 */
@media (max-width: 750px) {
  .car-image-container {
    width: 100rpx;
    height: 100rpx;
  }
  
  .car-name {
    font-size: 28rpx;
  }
  
  .car-description {
    font-size: 24rpx;
  }
  
  .car-price {
    font-size: 26rpx;
  }
}
</style>